<template>
  <div id="main">
    <div style="display: flex;justify-content: center">
      <img src="../assets/index_neusoft.png" alt="">
    </div>
    <div style="height: 40px;background-color: #F4F4F4;border-bottom: 2px solid #838383">
      <span style="line-height: 40px;margin-left: 30px;letter-spacing: 5px;font-weight: bolder">登录</span>
    </div>
    <div style="height: 300px">
      <p style="font-size: 25px;padding: 30px 30px 30px 30px;letter-spacing: 3px;text-align: center">欢迎使用东软会议室管理系统</p>
      <div style="width: 500px;margin-left: 222px;margin-right: 222px">
        <!-- <el-input placeholder="请输入用户名" prefix-icon="el-icon-user-solid"  v-model="loginData.uname"></el-input>
        <el-input style="margin-top: 10px" placeholder="请输入密码" prefix-icon="el-icon-lock" v-model="upwd"></el-input> -->
        <el-form ref="login" :model="loginForm" :rules="rules" class="login_form" label-width="0px">
                      <!-- 用户名 -->
                     <el-form-item prop="uname">
                       <el-input v-model="loginForm.uname" prefix-icon="iconfont icon-guanliyuan"  ></el-input>
                     </el-form-item> 
                     <!-- 密码 -->
                     <el-form-item prop="upwd">
                       <el-input v-model="loginForm.upwd" prefix-icon="iconfont icon-mima" type="password" ></el-input>
                     </el-form-item> 
                     <!-- 按钮 -->
                     <el-form-item class="btncss">
                       <el-button type="primary" @click="ok">登陆</el-button>
                       <el-button type="info" @click="reForm">重置</el-button>
                     </el-form-item> 
                  </el-form>    
        <div style="display: flex;margin-top: 10px;justify-content: space-between">
          
      
        </div>
      </div>
      
    </div>
  </div>
</template>

<script>
import axios from "axios";
import Qs from 'qs'

export default {
  name: "login.vue",
  data(){
    return{
      //提交对象
     loginForm:{
         uname:'张小红',
         upwd:'xiaohong'
     },
      rules:{
       uname:[
           { required: true, message: '用户名不能为空', trigger:'blur' },
           { min: 3, max: 18, message: '长度在 3 到 18 个字符', trigger: 'blur' }//长度验证
       ],
       upwd:[
         { required: true, message: '密码不能为空', trigger: 'blur' },
            { min: 6, max: 12, message: '长度在 6 到 12 个字符', trigger: 'blur' }
       ]
     }
      
    }
  },
  methods: {
    reForm(){
      this.$refs.login.resetFields();
    },

    ok(){
      // this.$router.push('/index')
      
      // valid 表单验证之后的布尔值，true表示成功，false表示失败
      this.$refs.login.validate(async valid =>{
          if(!valid)return;
         const {data:res} = await this.axios.post("login",this.loginForm);
         if(res.flag=="200"){
           this.$message.success("登陆成功");
           console.log(res.data)
           this.$router.push('/index')
           console.log(res.data.userid);
           window.localStorage.setItem("access-token",JSON.stringify(res.data))
          
           
           
       }else{
           this.$message.error("用户名或密码错误");
         }
     })
    },
    
    /*
    * @author: Zhang Lin
    * @date: 2022-04-12
    * @description: 取消登录方法
    * */
  
  }
}
</script>

<style scoped>
  #main{
    left: 50%;
    position: absolute;
    transform: translate(-50%);
    border: 2px solid rgba(0, 0, 0, 0.12);
    width: 945px;
    margin-top: 70px;
    border-radius: 15px;
    box-shadow: rgba(0, 0, 0, 0.25) 0px 54px 55px, rgba(0, 0, 0, 0.12) 0px -12px 30px, rgba(0, 0, 0, 0.12) 0px 4px 6px, rgba(0, 0, 0, 0.17) 0px 12px 13px, rgba(0, 0, 0, 0.09) 0px -3px 5px;
  }
</style>
